package com.rightsidetech.http.controller.agentAdmin.system;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.OperatorLogReq;
import com.rightsidetech.system.dtos.request.agent.SysAgentInfoPageReq;
import com.rightsidetech.system.dtos.response.OperatorLogResp;
import com.rightsidetech.system.dtos.response.agent.SysAgentInfoResp;
import com.rightsidetech.system.entity.SysAgentLoginInfo;
import com.rightsidetech.system.service.SysAdminAgentService;
import com.rightsidetech.system.service.SysAgentInfoService;
import com.rightsidetech.system.service.SysAgentOperatorLogService;
import com.rightsidetech.system.service.SysOperatorLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: yhr
 * @Date: 2021-11-18 14:43
 */
@RestController
@RequestMapping("/agentAdmin/sys_agent_log")
@ShenyuSpringMvcClient(path = "/agentAdmin/sys_agent_log/**")
@Api(tags = "代理商日志")
public class SysAgentOperatorLogController extends BaseController {
    @Resource
    private SysAgentOperatorLogService sysAgentOperatorLogService;
    @Resource
    private SysAgentInfoService sysAgentInfoService;
    @Resource
    private SysOperatorLogService sysOperatorLogService;

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/page")
    @ApiOperation("操作日志列表")
    public ResponseData<PageInfo<OperatorLogResp>> selectPage(OperatorLogReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        SysAgentLoginInfo loginInfo = sysAgentInfoService.selectInfoById(loginInfoId);
        if (ObjectUtils.isEmpty(loginInfo)) {
            return ResponseData.fail(CodeIdEnum.NOLOGINACCOUNT);
        }
        return sysAgentOperatorLogService.page(req, loginInfo.getAgentInfoId());
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/search")
    @ApiOperation("操作人员下拉框加载数据")
    public ResponseData selectList() throws Exception {
        return sysAgentOperatorLogService.selectList();
    }

    @Log
    @Token
    @Auth(bizType = Auth.AGENT)
    @GetMapping("/searchMethod")
    @ApiOperation("操作模块下拉框加载数据")
    public ResponseData selectMethodList() throws Exception {
        return sysOperatorLogService.selectMethodList((byte) 1);
    }
}
